<?php
add_action('widgets_init','reedwan_adds468x60_load_widgets');


function reedwan_adds468x60_load_widgets(){
		register_widget("Reedwan_Adds468x60_Widget");
}

class Reedwan_Adds468x60_Widget extends WP_widget{
	
	function Reedwan_Adds468x60_Widget(){
		$widget_ops = array('classname' => 'reedwan_adds468x60_widget', 'description' => 'Adds 468x60 for sidebar widget');

		$control_ops = array('id_base' => 'reedwan_adds468x60_widget');

		$this->WP_Widget('reedwan_adds468x60_widget', 'Adds 468x60', $widget_ops, $control_ops);
		
	}
	
	function widget($args,$instance){
		extract($args);
		echo $before_widget;
		$link = $instance['link'];
		$image = $instance['image'];
		$code = $instance['code'];
		?>
		<?php
		if($image) {	
		?>				
			<div class="adds468x60"><a href="<?php echo $link; ?>"><img src="<?php echo $image; ?>"/></a></div>
		<?php
		}
		else {
		?>
			<div class="adds468x60"><?php echo stripslashes($code); ?></div>
		<?php
		}
		echo $after_widget;
	}
	
	function update($new_instance, $old_instance){
		$instance = $old_instance;
		
		$instance['link'] = $new_instance['link'];
		$instance['image'] = $new_instance['image'];
		$instance['code'] = $new_instance['code'];
		
		return $instance;
	}
	
	function form($instance){
		?>
		<h3>Using Image </h3>
		<p>
			<label for="<?php echo $this->get_field_id('link'); ?>">Url:</label>
			<input class="widefat" style="width: 216px;" id="<?php echo $this->get_field_id('link'); ?>" name="<?php echo $this->get_field_name('link'); ?>" value="<?php echo $instance['link']; ?>" />
		</p>
		
		<p>
			<label for="<?php echo $this->get_field_id('image'); ?>">Image Url:</label>
			<input class="widefat" style="width: 216px;" id="<?php echo $this->get_field_id('image'); ?>" name="<?php echo $this->get_field_name('image'); ?>" value="<?php echo $instance['image']; ?>" />
		</p>
		<h3 style='margin-top: 40px;'>Or Using Code</h3>
		<p>
		
			<textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('code'); ?>" name="<?php echo $this->get_field_name('code'); ?>"><?php echo $instance['code']; ?></textarea>
		</p>
		<?php

	}
}
?>